package com.ziyia.a4_3_1;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.widget.Button;

public class MainActivity extends AppCompatActivity {

    private static final String TAG = "生命周期日志";


    /**
     * activity第一次创建时被调用
     * @param savedInstanceState
     */
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Log.d(TAG,"--------onCreate--------");
        //加载布局
        setContentView(R.layout.activity_main);
    }

    /**
     * activity从后台重新回到前台(由不可见变为可见)时被调用
     */
    @Override
    protected void onStart() {
        super.onStart();
        Log.d(TAG,"--------onStart--------");
    }

    /**
     * Activity准备好和用户进行交互的时候被调用
     */
    @Override
    protected void onResume() {
        super.onResume();
        Log.d(TAG,"--------onResume--------");
    }

    /**
     * Activity准备去启动或者恢复另一个Activity的时候调用
     */
    @Override
    protected void onPause() {
        super.onPause();
        Log.d(TAG,"--------onPause--------");
    }

    /**
     * 退出当前Activity或者跳转到新Activity时被调用
     * Activity完全不可见的时候调用
     */
    @Override
    protected void onStop() {
        super.onStop();
        Log.d(TAG,"--------onStop--------");
    }

    /**
     * 退出当前Activity时被调用,调用之后Activity就结束了
     */
    @Override
    protected void onDestroy() {
        super.onDestroy();
        Log.e(TAG,"--------onDestroy--------");
    }

    /**
     * Activity从后台重新回到前台时被调用
     */
    @Override
    protected void onRestart() {
        super.onRestart();
        Log.e(TAG,"--------onRestart--------");
    }

    public void alert(View view) {
        Intent intent = new Intent(this, SecondActivity.class);
        startActivity(intent);
    }

    public void finish(View view) {
        finish();
    }

    public void activity2(View view) {
        Intent intent = new Intent(this, MainActivity2.class);
        startActivity(intent);
    }
}